var centerLatitude = -38.88040994507488;
var centerLongitude = -62.07502663179184;
var startZoom = 15;
var map;

/**
* Initializes the map
**/
function init() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.removeMapType(G_NORMAL_MAP);
		//map.addMapType(G_SATELLITE_MAP);
        map.addMapType(G_DEFAULT_MAP_TYPES);
		//map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
		//clean the map
		map.clearOverlays();

		//-------------------------------------------------------
		//add Custom Controls
		//-------------------------------------------------------	
		function cleanControl(){};
		cleanControl.prototype = new GControl(true);
		cleanControl.prototype.initialize = function(map) {
		var container = document.createElement("div");
			//container.innerHTML = '<img style="cursor:pointer" src="./images/limpiar.png" border="0">';
			container.innerHTML = '<button class="ui-state-active ui-button ui-state-default ui-button-text-only ui-corner-all ui-state-hover"><span class="ui-button-text">Limpiar</span></button>';
			container.style.width='auto';
			container.style.height='auto';
			container.title = "Limpiar las busquedas";
			url = this.url_;
			GEvent.addDomListener(container, "click", function() {
				init();
			});
			map.getContainer().appendChild(container);
			return container;
		};
		cleanControl.prototype.getDefaultPosition = function() {
			return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 45));
		};		
		map.addControl(new cleanControl);
		//------------------------------------------------------
		function deturnoControl(){};
		deturnoControl.prototype = new GControl(true);
		deturnoControl.prototype.initialize = function(map) {
		var container = document.createElement("div");
			//container.innerHTML = '<img style="cursor:pointer" src="./images/limpiar.png" border="0">';
			container.innerHTML = '<button class="ui-state-active ui-button ui-state-default ui-button-text-only ui-corner-all ui-state-hover"><span class="ui-button-text" style="background:#049B02;">De Turno</span></button>';
			container.style.width='auto';
			container.style.height='auto';
			container.title = "Farmacias de Turno";
			url = this.url_;
			GEvent.addDomListener(container, "click", function() {
				deturno();
			});
			map.getContainer().appendChild(container);
			return container;
		};
		deturnoControl.prototype.getDefaultPosition = function() {
			return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 5));
		};		
		map.addControl(new deturnoControl);		
		//------------------------------------------------------
		//we add kml file		
		var green_kml = new GGeoXml("../green.kml?date="+(new Date().getTime()));
		map.addOverlay(green_kml);
		
		//add the markers defined in the data file
		//--	EVENTS	---------------

		//create a tip with a click!!!!!
		/*
		GEvent.addListener(map, "click", function(overlay, latlng){
			var marker = new GMarker(latlng);
			map.addOverlay(marker);
		});
				
		GEvent.addListener(map, "click", function(overlay, latlng) {
			//create an HTML DOM form element
			var inputForm = document.createElement("form");
			inputForm.setAttribute("action","");
			inputForm.onsubmit = function() {storeMarker(); return false;};
			//retrieve the longitude and lattitude of the click point
			var lng = latlng.lng();
			var lat = latlng.lat();
			inputForm.innerHTML = '<fieldset style="width:150px;">'
				+ '<legend>New Marker</legend>'
				+ '<label for="found">Found</label>'
				+ '<input type="text" id="found" style="width:100%;"/>'
				+ '<label for="left">Left</label>'
				+ '<input type="text" id="left" style="width:100%;"/>'
				+ '<label for="left">Icon URL</label>'
				+ '<input type="text" id="icon" style="width:100%;"/>'				
				+ '<input type="submit" value="Save"/>'
				+ '<input type="hidden" id="longitude" value="' + lng + '"/>'
				+ '<input type="hidden" id="latitude" value="' + lat + '"/>'
				+ '</fieldset>';
			map.openInfoWindow (latlng,inputForm);
		});
		*/
	}
}